/*
 * @Author: hongbin
 * @Date: 2023-05-21 21:59:29
 * @LastEditors: hongbin
 * @LastEditTime: 2023-08-09 15:13:05
 * @Description:
 */
import { FC } from "react";
import * as THREE from "three";
import { ThreeHelper } from "@/ThreeHelper";
import Layout from "@/components/Three/Layout";
import { gsap } from "gsap";
import { MethodBaseSceneSet } from "@/decorators";
import { Planet } from "@/components/particle/Planet";
import { Aircraft } from "@/components/particle/Aircraft";
import { Station } from "@/components/particle/Station";
import {
    BlendFunction,
    EffectComposer,
    EffectPass,
    NoiseEffect,
    RenderPass,
} from "postprocessing";
import { NoiseBg } from "./noiseBg";

interface IProps {}

const destroyEvent = [] as VoidFunction[];

const Index: FC<IProps> = () => {
    return (
        <>
            <Layout
                seoTitle={"星图"}
                init={Main.init}
                destroy={() => destroyEvent.forEach((destroy) => destroy())}
            />
            <div
                id="container"
                style={{
                    height: "1000vh",
                    width: "100%",
                }}
            ></div>
        </>
    );
};

export default Index;

class Main {
    @MethodBaseSceneSet
    static init(helper: ThreeHelper) {
        // helper.controls.enableZoom = false;
        const cameraWrap = new THREE.Object3D();
        helper.add(cameraWrap);
        cameraWrap.add(helper.camera);

        // const composer = new EffectComposer(helper.renderer);
        // var renderPass = new RenderPass(helper.scene, helper.camera);
        // renderPass.renderToScreen = false;
        // composer.addPass(renderPass);

        // const noiseEffect = new NoiseEffect({
        //     blendFunction: BlendFunction.ADD,
        // });
        // noiseEffect.blendMode.opacity.value = 0.1;

        // const standardPass = new EffectPass(helper.camera, noiseEffect);
        // composer.addPass(standardPass);

        // helper.render = () => {
        //     composer.render(helper.clock.getDelta());
        // };
        // const noiseBg = new NoiseBg(helper.camera);
        // helper.add(noiseBg.mesh);

        helper.gui
            ?.add({ enableZoom: true }, "enableZoom")
            .onChange((enableZoom) => {
                helper.controls.enableZoom = enableZoom;
            });
        helper.gui
            ?.add({ f: () => helper.camera.position.set(0, 0, 40) }, "f")
            .name("相机归正");

        const { ScrollTrigger } = require("gsap/ScrollTrigger");
        const { ScrollToPlugin } = require("gsap/ScrollToPlugin");
        gsap.registerPlugin(ScrollTrigger, ScrollToPlugin);

        new Station();
        new Planet();
        new Aircraft();
    }
}
